package com.zyh.stu.system.controller;

import com.zyh.stu.system.dao.impl.StudentDaoImpl;
import com.zyh.stu.system.domain.Student;
import com.zyh.stu.system.service.impl.UserServiceImpl;

import java.util.Scanner;

public class StudentController {
    public static final Scanner INPUT = new Scanner(System.in);

    //创建StudentDaoImpl对象
    public static final UserServiceImpl serviceImpl = new UserServiceImpl();

    public static void main(String[] args) {
        outer:
        while (true) {
            System.out.println("--------欢迎来到学生管理系统--------");
            System.out.println("1 添加学生");
            System.out.println("2 删除学生");
            System.out.println("3 修改学生");
            System.out.println("4 查看学生");
            System.out.println("5 退出");
            System.out.println("请输入您的选择:");
            int choice = INPUT.nextInt();
            switch (choice) {
                case 1://添加学生
                    System.out.println("请输入您要添加的学生编号");
                    String sid = INPUT.next();
                    int addIndex = serviceImpl.findById(sid);
                    if (addIndex!=-1){
                        System.out.println("您输入的编号重复了！");
                        continue outer;
                    }
                    System.out.println("请输入您要添加的学生姓名");
                    String name = INPUT.next();
                    System.out.println("请输入您要添加的学生年龄");
                    int age = INPUT.nextInt();
                    System.out.println("请输入您要添加的学生生日");
                    String birthday = INPUT.next();
                    Student student = new Student(sid, name, age, birthday);
                    serviceImpl.add(student);
                    break;
                case 2://删除学生
                    System.out.println("请输入需要删除学生的sid");
                    String stuId = INPUT.next();
                    serviceImpl.delete(stuId);
                    break;
                case 3://修改学生
                    System.out.println("请输入需要修改学生的sid");
                    String newSid = INPUT.next();
                    int stuIndex = serviceImpl.findById(newSid);
                    if (stuIndex==-1){
                        System.out.println("您要修改的学生信息不存在！");
                        continue outer;
                    }
                    System.out.println("请输入需要修改学生的姓名");
                    String newName = INPUT.next();
                    System.out.println("请输入需要修改学生的年龄");
                    int newAge = INPUT.nextInt();
                    System.out.println("请输入需要修改学生的生日");
                    String newBirthday = INPUT.next();
                    Student student1 = new Student(newSid, newName, newAge, newBirthday);
                    serviceImpl.update(student1);
                    break;
                case 4://查询所有学生
                    serviceImpl.findAll();
                    break;
                default:
                    System.out.println("系统退出！");
                    System.exit(0);
            }
        }
    }
}
